<?php

namespace app\admin\controller\ai;

use app\common\controller\BaseController;
use hg\apidoc\annotation as Apidoc;
use app\common\service\ai\MemberService;
use app\common\service\ai\PromoterService;

/**
 * @Apidoc\Title("会员管理")
 * @Apidoc\Group("ai")
 * @Apidoc\Sort("300")
 */
class Member extends BaseController {

    /**
     * @Apidoc\Title("列表")
     * @Apidoc\Param("keyword", type="string", require=true, desc="关键字搜索")
     * @Apidoc\Param(ref="app\common\model\ai\MemberModel", field="create_time")
     * @Apidoc\Returned("list", type="array", desc="列表", children={
     * @Apidoc\Returned(ref="app\common\model\ai\MemberModel", withoutField="sdc"),
     * @Apidoc\Returned("is_promoter", type="int", require=true, desc="是否分销员(0否,1是)"),
     * })
     */
    public function getList() {
        $list = MemberService::getListByAdmin($this->data);
        return success($list);
    }
    
    /**
     * @Apidoc\Title("详情")
     * @Apidoc\Param(ref="app\common\model\ai\MemberModel", field="id")
     * @Apidoc\Returned(ref="app\common\model\ai\MemberModel", withoutField="sdc"),
     * })
     */
    public function getDetail() {
        $result = MemberService::getDetailByAdmin($this->data);
        return success($result);
    }
    
    /**
     * @Apidoc\Title("新增")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="app\common\model\ai\MemberModel", field="nickname,username,phone,password,headimgurl")
     * })
     */
    public function add() {
        MemberService::add($this->data);
    }
    
    /**
     * @Apidoc\Title("编辑")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="app\common\model\ai\MemberModel", field="member_id,nickname,username,phone,password,headimgurl")
     * })
     */
    public function edit() {
        MemberService::edit($this->data);
    }
    
    /**
     * @Apidoc\Title("充点")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="app\common\model\ai\MemberModel", field="member_id,point")
     * })
     */
    public function recharge() {
        MemberService::recharge($this->data);
    }
    
    /**
     * @Apidoc\Title("扣点")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="app\common\model\ai\MemberModel", field="member_id")
     * @Apidoc\Param(ref="app\common\model\ai\OrderModel", field="point")
     * })
     */
    public function reduce() {
        MemberService::reduce($this->data);
    }
    
    /**
     * @Apidoc\Title("设为分销员")
     * @Apidoc\Method("POST")
     * @Apidoc\Param(ref="app\common\model\ai\MemberModel", field="member_id")
     * })
     */
    public function setPromoter() {
        PromoterService::add($this->data);
    }

}
